home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / wcedlgpr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  5.9 KB  |  243 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #if !defined(_WIN32_WCE_NO_PRINTING)
  14.  
  15. #ifdef AFX_AUX_SEG
  16. #pragma code_seg(AFX_AUX_SEG)
  17. #endif
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. #define new DEBUG_NEW
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Print/Print Setup dialog
  28.  
  29. BEGIN_MESSAGE_MAP(CPrintDialog, CCommonDialog)
  30.     //{{AFX_MSG_MAP(CPrintDialog)
  31.     //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33.  
  34. CPrintDialog::CPrintDialog(BOOL bPrintSetupOnly, 
  35.     DWORD dwFlags, CWnd* pParentWnd) 
  36.     : m_pd(m_pdActual), CCommonDialog(pParentWnd) 
  37. {
  38.     ASSERT(bPrintSetupOnly == FALSE); 
  39.     memset(&m_pdActual, 0, sizeof(m_pdActual)); 
  40.  
  41.     m_pd.cbStruct = sizeof(m_pdActual);
  42.     m_nIDHelp = AFX_IDD_PRINT;
  43.        m_nFromPage = 1; 
  44.        m_nToPage   = 0xffff; 
  45.        m_nMinPage  = 1; 
  46.        m_nMaxPage  = 0xffff; 
  47.        m_nCopies   = 1;
  48. }
  49.  
  50. CPrintDialog::CPrintDialog(PRINTDLG& pdInit)
  51.     : m_pd(pdInit), CCommonDialog(NULL)
  52. {
  53. }
  54.  
  55. CPrintDialog* CPrintDialog::AttachOnSetup()
  56. {
  57.     ASSERT_VALID(this);
  58.  
  59.     CPrintDialog* pDlgSetup;
  60.  
  61.     pDlgSetup = new CPrintDialog(m_pd);
  62.     pDlgSetup->m_hWnd = NULL;
  63.     pDlgSetup->m_pParentWnd = m_pParentWnd;
  64.     pDlgSetup->m_nIDHelp = AFX_IDD_PRINTSETUP;
  65.     return pDlgSetup;
  66. }
  67.  
  68. int CPrintDialog::DoModal()
  69. {
  70.     ASSERT_VALID(this);
  71.     
  72.     m_pd.hwndOwner = PreModal(); 
  73.  
  74.     if(m_pd.hdc != NULL)
  75.     {
  76.         DeleteDC(m_pd.hdc);
  77.         m_pd.hdc = NULL;
  78.     }
  79.  
  80.     PRINTDLG pd = m_pd;
  81.     int nResult = ::PrintDlg(&pd);
  82.     m_pd = pd;
  83.  
  84.     PostModal();
  85.  
  86.     return nResult ? nResult : IDCANCEL;
  87. }
  88.  
  89. int CPrintDialog::GetCopies() const
  90. {
  91.     return m_nCopies;
  92. }
  93.  
  94. #define REG_PRINTER_VALUE_SIZE 40
  95.  
  96. CString CPrintDialog::GetDeviceName() const
  97. {
  98.     HKEY    hKeyPrinters;
  99.     LPTSTR  lpszPrinters = _T("Printers");
  100.     TCHAR   szValueName[REG_PRINTER_VALUE_SIZE] = _T("");
  101.     TCHAR    szValue[REG_PRINTER_VALUE_SIZE] = _T("");
  102.  
  103.     if(WCE_FCTN(RegOpenKey)(HKEY_LOCAL_MACHINE, lpszPrinters, &hKeyPrinters) == ERROR_SUCCESS )
  104.     {
  105.         DWORD dwSizeValueName = REG_PRINTER_VALUE_SIZE;
  106.         DWORD dwSizeValue = REG_PRINTER_VALUE_SIZE;
  107.         DWORD dwType = REG_SZ;
  108.         int iKeyPrinter = 0;
  109.  
  110.         while(RegEnumValue(hKeyPrinters, iKeyPrinter, szValueName, &dwSizeValueName, NULL, &dwType, 
  111.               (LPBYTE)szValue, &dwSizeValue) == ERROR_SUCCESS)
  112.         {
  113.             if(!lstrcmp(szValueName, _T("DefaultPrinter")))
  114.                 break;
  115.         
  116.             iKeyPrinter++;
  117.             dwSizeValueName = REG_PRINTER_VALUE_SIZE;
  118.             dwSizeValue = REG_PRINTER_VALUE_SIZE;
  119.         }
  120.         RegCloseKey(hKeyPrinters);
  121.     }
  122.     return CString(szValue);
  123. }
  124.  
  125. CString CPrintDialog::GetPortName() const
  126. {
  127.     CString csPrinter = GetDeviceName();
  128.  
  129.     HKEY    hKeyPrinters;
  130.     TCHAR   lpszPrinter[REG_PRINTER_VALUE_SIZE * 2] = _T("Printers\\");
  131.     TCHAR   szValueName[REG_PRINTER_VALUE_SIZE] = _T("");
  132.     TCHAR    szValue[REG_PRINTER_VALUE_SIZE] = _T("");
  133.  
  134.     lstrcat(lpszPrinter, (LPCTSTR)csPrinter.GetBuffer(REG_PRINTER_VALUE_SIZE));
  135.     csPrinter.ReleaseBuffer();
  136.  
  137.     if(WCE_FCTN(RegOpenKey)(HKEY_LOCAL_MACHINE, (LPCTSTR)lpszPrinter, &hKeyPrinters) == ERROR_SUCCESS )
  138.     {
  139.         DWORD dwSizeValueName = REG_PRINTER_VALUE_SIZE;
  140.         DWORD dwSizeValue = REG_PRINTER_VALUE_SIZE;
  141.         DWORD dwType = REG_SZ;
  142.         int iKeyPrinter = 0;
  143.  
  144.         while(RegEnumValue(hKeyPrinters, iKeyPrinter, szValueName, &dwSizeValueName, NULL, &dwType, 
  145.               (LPBYTE)szValue, &dwSizeValue) == ERROR_SUCCESS)
  146.         {
  147.             if(!lstrcmp(szValueName, _T("Port")))
  148.                 break;
  149.         
  150.             iKeyPrinter++;
  151.             dwSizeValueName = REG_PRINTER_VALUE_SIZE;
  152.             dwSizeValue = REG_PRINTER_VALUE_SIZE;
  153.         }
  154.         RegCloseKey(hKeyPrinters);
  155.     }
  156.     return CString(szValue);
  157. }
  158.  
  159. BOOL CPrintDialog::GetDefaults()
  160. {
  161.     m_pd.dwFlags |= PD_RETURNDEFAULTDC;
  162.  
  163.     if(m_pd.hdc != NULL)
  164.     {
  165.         DeleteDC(m_pd.hdc);
  166.         m_pd.hdc = NULL;
  167.     }
  168.  
  169.     PRINTDLG pd = m_pd;
  170.     int nResult = ::PrintDlg(&pd);
  171.     m_pd = pd;
  172.  
  173.     return nResult;
  174. }
  175.  
  176. // WinCE-only: substitute for CPageSetupDialog::GetPaperSize()
  177. CSize CPrintDialog::GetPaperSize() const
  178. {
  179.     CSize size;
  180.  
  181.     if(m_pd.dwFlags & PD_SELECTA4) // 21.0 cm x 29.7 cm
  182.     {
  183.         if(m_pd.dwFlags & PD_INHUNDREDTHSOFMILLIMETERS)
  184.         {
  185.             size.cx = 21000;  // 21.0 * 10 * 100
  186.             size.cy = 29700;  // 29.7 * 10 * 100
  187.         }
  188.         else // PD_INTHOUSANDTHSOFINCHES assumed
  189.         {
  190.             size.cx = 210*254; // 21.0 * 2.54 * 1000
  191.             size.cy = 297*254; // 29.7 * 2.54 * 1000
  192.         }
  193.     }
  194.     else // PD_SELECTLETTER assumed  11.0 in x 8.5 in
  195.     {
  196.         if(m_pd.dwFlags & PD_INHUNDREDTHSOFMILLIMETERS)
  197.         {
  198.             size.cx = (int)(8500.0 / 2.54); // 8.5 / 2.54 * 10 * 100; 
  199.             size.cy = (int)(11000.0 / 2.54); // 11.0 / 2.54 * 10 * 100; 
  200.         }
  201.         else // PD_INTHOUSANDTHSOFINCHES assumed
  202.         {
  203.             size.cx = 8500;   // 8.5 * 1000
  204.             size.cy = 11000;  // 11.0 * 1000
  205.         }
  206.     }
  207.  
  208.     return size;
  209. }
  210.  
  211. // WinCE-only: substitute for CPageSetupDialog::GetMargins()
  212. void CPrintDialog::GetMargins(LPRECT lpRectMargins, LPRECT lpRectMinMargins) const
  213. {
  214.     if (lpRectMargins != NULL)
  215.         memcpy(lpRectMargins, &m_pd.rcMargin, sizeof(RECT));
  216.     if (lpRectMinMargins != NULL)
  217.         memcpy(lpRectMinMargins, &m_pd.rcMinMargin, sizeof(RECT));
  218. }
  219.  
  220. ////////////////////////////////////////////////////////////////////////////
  221. // CPrintDialog diagnostics
  222.  
  223. #ifdef _DEBUG
  224. void CPrintDialog::Dump(CDumpContext& dc) const
  225. {
  226.     CDialog::Dump(dc);
  227.  
  228.     dc << "m_pd.hwndOwner = " << (UINT)m_pd.hwndOwner;
  229.     if (m_pd.hdc != NULL)
  230.         dc << "\nm_pd.hdc = " << CDC::FromHandle(m_pd.hdc);
  231.     dc << "\nm_pd.dwFlags = " << (LPVOID)m_pd.dwFlags;
  232.     dc << "\n";
  233. }
  234. #endif //_DEBUG
  235.  
  236. #ifdef AFX_INIT_SEG
  237. #pragma code_seg(AFX_INIT_SEG)
  238. #endif
  239.  
  240. IMPLEMENT_DYNAMIC(CPrintDialog, CCommonDialog)
  241.  
  242. ////////////////////////////////////////////////////////////////////////////
  243. #endif // _WIN32_WCE_NO_PRINTING